/**
  * @Description: WoShop商城
  * @Author: 梧桐
  * @Copyright: 武汉一一零七科技有限公司©版权所有
  * @Link: www.s1107.com
  * @Contact: QQ:2487937004
  */
 <template>
    <view class="page">
	<u-field
			v-model="number"
			label="手机号"
            required
			placeholder="请输入正确的手机号"
		>
		</u-field>
        	<u-field
			v-model="code"
			label="验证码"
            required
			placeholder="请输入验证码"
            maxlength="6"
		>
        <u-button size="mini" slot="right" type="success" @click="encode">{{coun}}</u-button>
		</u-field>
        	<u-field
			v-model="pwd"
			label="登录密码"
            required
			placeholder="请输入密码"
		>
		</u-field>
    	<u-field
			v-model="repwd"
			label="登录密码"
            required
			placeholder="再次输入密码"
		>
		</u-field>
    
        <u-button type="warning"  class="u-m-t-20" @click="register">提交</u-button>
        
    </view>
</template>

<script>
let num = 60
export default {
    data(){
        return {
            number:'',
            coun : '',
            code:'',
            pwd:'',
            repwd:''
            
        }
    },
   onLoad(){
      this.coun = '获取验证码'
   },
    methods: {
        register:function(){
            if(this.number.length < 11) {
                this.$toast('请输入正确的手机号')
                return false
            }
            if(this.code == '') {
                this.$toast('请输入验证码')
                return false
            }
            if(this.pwd.length < 6) {
                this.$toast('请输入密码长度不小于6位数的密码')
                return false
            }
            if(this.repwd.length < 6) {
                this.$toast('请输入密码长度不小于6位数的密码')
                return false
            }
            if(this.pwd != this.repwd ) {
                this.$toast('两次输入的密码不一致')
                return false
            }
            this.$http.getshezhi({
                phone:this.number,
                phonecode:this.code,
                password:this.pwd,
                repwd:this.repwd,
               
            }).then(res=>{
                if(res.status == 200) {
                    this.$toast(res.mess)
                    setTimeout(() => {
                        this.getback()
                    }, 1500);
                }
                
            })
        },
        encode:function(){
            if(this.number.length < 11) {
                this.$toast('请输入正确的手机号')
                return false
            }
            this.$http.getsendcodeWx({phone: this.number}).then(res=>{
                if(res.status == 200) {
                    this.$toast(res.mess)
                    var timeId = setInterval( res=>{
                        --num
                        if(num == 0) {
                            this.coun = '重新获取'
                            clearInterval(timeId)
                            num = 60
                        return false
                        }
                        this.coun = num + 's'
                       
                    } ,1000)
                }
            })
        }
    },
}
</script>

<style>
.page{
    background:#fff;
    padding:25upx;
}
</style>
